﻿// ------------------------------------------------------------------------------
// Copyright  陶伟个人 版权所有。
// 项目名：ElasticsearchCore.ElasticSearch
// 文件名：ElasticSearchSourceConfig.cs
// 创建标识：陶伟 2018-07-17 13:30
// 创建描述：
//
// 修改标识：陶伟2018-07-17 13:30
// 修改描述：
//  ------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using ElasticsearchCore.Util;

namespace ElasticsearchCore.ElasticSearch.Config
{

    /// <summary>
    ///     ElasticSearchSourceConfig
    /// </summary>
    public class ElasticSearchSourceConfig
    {

        private static string GetValueFromXml(string elementName)
        {
            var filepath = AppDomain.CurrentDomain.BaseDirectory + @"/Config/ElasticSearch.config";
            string result;
            var fileDependency = new CacheDependency(filepath);
            //var cache = DataCache.GetCache("SystemParam_ConfigFile_" + elementName);
            //if (cache == null)
            //{
            //    XElement xml = XElement.Load(filepath);
            //    result = xml.Element(elementName).Value;
            //   // DataCache.SetCache("SystemParam_ConfigFile_" + elementName, result, fileDependency);
            //}
            //else
            //    result = cache.ToString();
            XElement xml = XElement.Load(filepath);
            result = xml.Element(elementName).Value;
            return result;
        }
        /// <summary>
        ///     Uri
        /// </summary>
        public List<string> Uris { get; set; }

        /// <summary>
        ///     DefaultIndex
        /// </summary>
        public string DefaultIndex { get; set; }

        public static ElasticSearchSourceConfig GetElasticSearchSourceConfig()
        {
            return new ElasticSearchSourceConfig()
            {
                Uris = GetValueFromXml("Uris").ToString().Split(',').ToList(),
                DefaultIndex = GetValueFromXml("DefaultIndex").ToString()
            };
        }
    }
}